<%@ page import="java.util.List" %>
<%@ page import="cn.edu.zut.model.Book" %>
<%@ page import="cn.edu.zut.model.BorrowBook" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户主页</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="/js/bootstrap.min.css">
    <script src="/js/jquery.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/bootstrap-table.min.js"></script>
    <script src="/js/bookstrapreader.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/userbook.css"/>
    <link rel="stylesheet" type="text/css" href="/css/userborrow.css"/>
</head>
<body>
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">
            <h2>欢迎您，用户${reader.name}</h2>

        </h3>
            <h3 style="text-align:right; color: #2e6da4"><a href = "javascript:void(0)" onclick = "document.getElementById('cont_b').style.display='block'">查看我的读者身份信息</a></h3>
        <h4>你的借书记录如下：</h4>
        <div id="cont_b" class="cont1">
                <%--点击查看读者信息名片后触发的页面,通过block和none来控制--%>
                <p style="text-align: right"><a href = "javascript:void(0)" onclick = "document.getElementById('cont_b').style.display='none'">关闭</a></p>
                你的读者名：${reader.name}<br>
                年龄：${reader.age}<br>
                性别：${reader.sex}<br>
                电话号码：${reader.phone}<br>
                职业或专业：${reader.dept}<br>
            </div>
    </div>
    <div class="panel-body">
        <table  class="table table-hover">
            <thead>
            <tr>
                <th>书本编号</th>
                <th>书名</th>
                <th>借阅时间</th>
                <th>应还时间</th>
                <th>状态</th>
            </tr>
            </thead>
            <tbody>
            <%
                List<Book> books=(List<Book>)session.getAttribute("books");
                List<BorrowBook> borrowBooks=(List<BorrowBook>)session.getAttribute("borrowBooks");
                String str1="<a href = \"javascript:void(0)\" onclick = \"document.getElementById('";
                String str2="').style.display='block'\">";//定义按钮触发事件
                for(BorrowBook borrowBook:borrowBooks){
                    out.println("<tr>");
                    out.println("<td>"+borrowBook.getBookId()+"</td>");
                    for(Book book:books){
                        if(book.getBookid()==borrowBook.getBookId()){//通过借阅图书的id号找到图书名战术
                            String str=str1+book.getBookid()+str2;
                            out.println("<td>"+str+book.getBookname()+"</a>"+"</td>");
                            pageContext.setAttribute("everyBookId",book.getBookid());
                         %>

                           <div id=${everyBookId} class="cont">
                               <%--点击图书名时触发的页面，弹出图书的详细信息--%>
                           <p style="text-align: right"><a href = "javascript:void(0)"
                                                           onclick = "document.getElementById(${everyBookId}).style.display='none'">关闭</a></p>

                               <div id = "s11">
                                   <h3>书籍信息</h3>
                               </div>
                               <div>
                                   <img src="/image/book.png"></img>
                               </div>
                               <div id="aa1">
                         <%
                           out.println("<p>书本ID:"+book.getBookid()+"</p>");
                           out.println("<p>书本ISBN:"+book.getIsbn()+"</p>");
                           out.println("<p>书本名:"+book.getBookname()+"</p>");
                           out.println("<p>书本作者:"+book.getAuthor()+"</p>");
                           out.println("<p>书本出版社:"+book.getIsbn()+"</p>");
                           out.println("<p>书本出版日期:"+book.getPublishdate()+"</p>");
                           out.println("<p>书本发行次数:"+book.getPublishtime()+"</p>");
                           out.println("<p>书本价格:"+book.getUnitprice()+"</p>");
                         %></div>
                         <%
                            break;
                        }
                    }
                    out.println("<td>"+new SimpleDateFormat("yyyy/MM/dd").format(borrowBook.getBorrowDate())+"</td>");//将date类型转化为字符串型
                    out.println("<td>"+new SimpleDateFormat("yyyy/MM/dd").format(borrowBook.getShouldReturn())+"</td>");
                    if(borrowBook.getFlag()==1){//通过借阅图书的状态判断是否还书
                        out.println("<td><b>"+"已还"+"</b></td>");
                    }
                    else{
                        out.println("<td><b>"+"未还"+"</b></td>");
                    }
                    out.println("</tr>");
                }
                       %>
            </tbody>
        </table>
    </div>
</div>

</body>
</html>
